class Car:
    """表示一辆汽车的类"""

    def __init__(self, make, model, year):
        """初始化汽车的制造商、型号和年份"""
        self.make = make
        self.model = model
        self.year = year
        self.odometer_reading = 0  # 默认里程数为0

    def get_descriptive_name(self):
        """返回汽车的描述性名称"""
        return f"{self.year} {self.make} {self.model}"

    def read_odometer(self):
        """打印汽车的里程数"""
        print(f"This car has {self.odometer_reading} miles on it.")

    def update_odometer(self, mileage):
        """更新汽车的里程数"""
        if mileage >= self.odometer_reading:
            self.odometer_reading = mileage
        else:
            print("You can't roll back an odometer!")


# 实例化对象
my_car = Car("Toyota", "Corolla", 2020)

# 访问实例属性和方法
print(my_car.get_descriptive_name())  # 输出: 2020 Toyota Corolla
my_car.read_odometer()  # 输出: This car has 0 miles on it.

# 更新里程数
my_car.update_odometer(23)
my_car.read_odometer()  # 输出: This car has 23 miles on it.

# 尝试回滚里程数
my_car.update_odometer(20)  # 输出: You can't roll back an odometer!